<template>
  <div class="box">
    <swiper :banner="banner"></swiper>
    <!--教材-->
    <div class="list">
      <!--<h3>教材免费学习 <span @click="$router.push('jiaocailist')">更多</span></h3>-->
<h3>教材免费学习  </h3>
      <ul>
        <li v-for="(v, k) in jcList" :key="k" @click="$router.push({path:'/jiaocaicontent',query:{'id':v.id,'is_mine':false}})">
          <img :src="v.publishing" alt="">
        </li>
      </ul>
    </div>
    <!--课程-->
    <div class="list">
     <!-- <h3>课程免费学习 <span @click="$router.push('course')">更多</span></h3>-->
<h3>课程免费学习 </h3>
      <ul>
        <li v-for="(v, k) in kcList" :key="k" @click="$router.push({path: '/contentlist', query: {id: v.id}})">
          <img :src="v.free_cover" alt="">
        </li>
      </ul>
    </div>
    <!--按钮-->
    <div class="btnbox">
      <button @click="$router.push('/course')" class="kc">购买课程</button>
      <button @click="$router.push('/jiaocailist')" class="jc">购买教材</button>
    </div>
  </div>
</template>

<script>
import Swiper from '../components/swiper'
import HomeItem from '../components/HomeItem'
import * as info from '../api/info'
export default {
  name: 'learn-free',
  components: {
    'swiper': Swiper,
    'home-item': HomeItem
  },
  data () {
    return {
      banner: [
        {
          url: '../../static/images/banner1.jpg'
        },
        {
          url: '../../static/images/banner2.jpg'
        },
        {
          url: '../../static/images/banner3.jpg'
        }
      ],
      kcList: [
        {
          id: 0,
          name: '日常英语口语学习课程',
          imgSrc: '../../static/images/kc.jpg'
        },
        {
          id: 1,
          name: '职场常用英语课程',
          imgSrc: '../../static/images/kc.jpg'
        },
        {
          id: 2,
          name: '日常英语口语学习课程',
          imgSrc: '../../static/images/kc.jpg'
        },
        {
          id: 3,
          name: '日常英语口语学习课程',
          imgSrc: '../../static/images/kc.jpg'
        }
      ],
      jcList: [
        {
          id: 0,
          name: '日常英语口语学习教材日常英语口语学习教材',
          imgSrc: '../../static/images/jc.jpg'
        },
        {
          id: 1,
          name: '职场常用英语教材',
          imgSrc: '../../static/images/jc.jpg'
        },
        {
          id: 2,
          name: '日常英语口语学习教材',
          imgSrc: '../../static/images/jc.jpg'
        },
        {
          id: 3,
          name: '日常英语口语学习教材',
          imgSrc: '../../static/images/jc.jpg'
        }
      ]
    }
  },
  methods: {
    getBanner () {
      info.getBanners(1, 5)
        .then(res => {
          this.banner = res.data
        })
    },
    getCourse () {
      // 获取所有课程
      info.getCourses({cate_id: 4, page: 1, perPage: 1})
        .then(res => {
          this.kcList = res.data
        })
    },
    getJiaoCai () {
      // 获取教材
      info.getBookList()
        .then(res => {
          this.jcList = res.data
        })
    }
  },
  mounted () {
    this.getBanner()
    this.getCourse()
    this.getJiaoCai()
  }
}
</script>

<style scoped>
.box{
  padding-bottom: 1.2rem;
}
.list h3{
  height: 1rem;
  line-height: 1rem;
  font-size: .4rem;
  color: #000;
  background: #e5e5e5;
  padding: 0 .3rem;
}
.list h3 span{
  font-size: .36rem;
  color: #666;
  float: right;
}
.list ul{
  padding: .3rem .3rem 0;
  display: flex;
  display: -webkit-flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.list li{
  width: 100%;
  margin-bottom: .2rem;
}
.list li img{
  display: block;
  width: 100%;
  border: 1px solid #d1d1d1;
}
.list li p{
  font-size: .38rem;
  color: #333;
  height: 1rem;
  line-height: 1rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  width: 100%;
}
.btnbox{
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: -webkit-flex;
  height: 1.1rem;
  display: flex;
  align-items: center;
  background: #007aff;
}
.btnbox button{
  width: 5rem;
  color: #fff;
  background: #007aff;
  border: none;
  line-height: 1.1rem;
  padding: 0;
  text-align: center;
}
.btnbox .kc{
  border-right: 1px solid #a1a1a1;
}
</style>
